'use strict';

const createValidate = {
  name: {
    type: 'string',
  },
  version: {
    type: 'string',
  },
  url: {
    type: 'string',
    required: false,
  },
  isShow: {
    type: 'boolean',
  },
  cover: {
    type: 'url',
  },
  describe: {
    type: 'string',
    required: false,
  },
  type: {
    type: 'string',
  },
  startDate: {
    type: 'w-date',
  },
  endDate: {
    type: 'w-date',
  },
  content: {
    type: 'string',
    required: false,
  },
}

exports.create = async ctx => {
  ctx.validate(createValidate);
  ctx.sendSuccess(await ctx.service.product.create());
};

exports.update = async ctx => {
  ctx.validate(createValidate);
  ctx.validate({
    id: {
      type: 'mongo-id',
    },
  }, ctx.params);
  ctx.sendSuccess(await ctx.service.product.update());
};

exports.destroy = async ctx => {
  ctx.validate({
    id: {
      type: 'mongo-id',
    },
  }, ctx.params);
  ctx.sendSuccess(await ctx.service.product.destroy());
};

